<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.googlecode.contests_repo.core.users.UserManager"%>
<% if (session.getAttribute("username") != null) {
	response.sendRedirect("resource.jsp");
} %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contest Repo - Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="assets/style/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<%@include file="include/header.jsp"%>
	<h1>Login</h1>
	<jsp:useBean id="user"
		class="com.googlecode.contests_repo.core.model.User" scope="request">
		<jsp:setProperty name="user" property="*" />
	</jsp:useBean>
	<%
	    if (request.getParameter("commit") != null) {
				boolean isAuthorized = UserManager.isAuthorizedUser(
				user.getLogin(), user.getPassword());
				if (isAuthorized) {
			    session.setAttribute("username", user.getLogin());
					response.sendRedirect("resource.jsp");
	    	} else {
	%>
				<p class="error">Invalid username or password!</p>
	<%
				}
	    }
	%>
	<form method="post" action="" class="login">
		<p>Username:</p>
		<p><input type="text" name="login" /></p>
		<p>Password:</p>
		<p><input type="password" name="password" /></p>
		<p><button name="commit" value="1">Login</button></p>
	</form>
</body>
</html>